package com.kaibes.core.base.builder;

import java.math.BigDecimal;

public class BigDecimalBuilder {

    private BigDecimal value;

    public BigDecimalBuilder(String value) {
        this.value = new BigDecimal(value);
    }

    public BigDecimalBuilder divide(double val) {
        BigDecimal bigDecimal = new BigDecimal(Double.toString(val));
        value = value.divide(bigDecimal);
        return this;
    }
    public BigDecimalBuilder divide(long val) {
        BigDecimal bigDecimal = new BigDecimal(Long.toString(val));
        value = value.divide(bigDecimal);
        return this;
    }
    
    // subtract
    public BigDecimalBuilder subtract(double val) {
        BigDecimal bigDecimal = new BigDecimal(val);
        value = value.subtract(bigDecimal);
        return this;
    }

    // multiply
    public BigDecimalBuilder multiply(String val) {
        value = value.multiply(new BigDecimal(val));
        return this;
    }

    public BigDecimalBuilder multiply(int val) {
        value = value.multiply(new BigDecimal(val));
        return this;
    }

    public BigDecimalBuilder multiply(double val) {
        value = value.multiply(new BigDecimal(val));
        return this;
    }

    public BigDecimalBuilder setScale(int scale) {
        value = value.setScale(scale, BigDecimal.ROUND_HALF_UP);
        return this;
    }

    // build
    public BigDecimal build() {
        return value;
    }

    // new
    public static BigDecimalBuilder newBuilder(String value) {
        return new BigDecimalBuilder(value);
    }

    public static BigDecimalBuilder newBuilder(double value) {
        return new BigDecimalBuilder(Double.toString(value));
    }
    
    public static BigDecimalBuilder newBuilder(long value) {
        return new BigDecimalBuilder(Long.toString(value));
    }

}
